/*
 * @Description: 
 * @Author: duan_shuangjun 丶
 * @Date: 2025-08-20 14:41:05
 * @LastEditTime: 2025-09-21 15:18:41
 */
import 'amfe-flexible'
import '@/shims/browserGlobals'
import { createApp } from 'vue'
import App from './App.vue'
import ElementPlus from 'element-plus'
import zhCn from 'element-plus/es/locale/lang/zh-cn'
import 'element-plus/dist/index.css'
import './style.css'
import './styles/index.scss'
import { createPinia } from 'pinia'
import router from './router'
import { LocalStorage } from '@/utils/storage'
import { useUserStore } from '@/stores/user'
import { createPrintQueueNotification } from '@/components/PrintQueueNotification'


const app = createApp(App)
app.use(ElementPlus, {
  locale: zhCn,
})
const pinia = createPinia()
app.use(pinia)
app.use(router)
// 初始化用户数据（如果有token）
const token: string = LocalStorage.get('token')
if (token) {
  const user = useUserStore(pinia)
  user.setToken(token as string)

  // 异步加载用户数据，失败时清除token
  user.initLoadUserProfile?.().catch((error) => {
    console.error('用户数据加载失败:', error)
    // 如果数据加载失败，清除token
    LocalStorage.remove('token')
    user.logout()
  })
}

app.mount('#app')

// 初始化打印队列通知组件
createPrintQueueNotification()

window.ipcRenderer?.on?.('main-process-message', (_event, message) => {
  console.log(message)
})
